#pragma once
#include <iostream>
#include <vector>

#define NUM 10
class union_table
{
public:
    union_table(int N = NUM)
    {
        _vt.resize(N, -1);
    }

    int find(int x)
    {
        while (_vt[x])
            x = _vt[x];
        return x;
    }

    bool _union(int x, int y)
    {
        int pos_x = find(x);
        int pos_y = find(y);
        _vt[pos_x] += _vt[pos_y];
        _vt[pos_y] = pos_x;
        return true;
    }

    bool issame(int x, int y)
    {
        int pos_x = find(x);
        int pos_y = find(y);
        if (pos_x != pos_y)
            return false;
        return true;
    }

    ~union_table()
    {
    }

private:
    std::vector<int> _vt;
};